#!/bin/sh

echo
echo "============================================"
echo "Install extensions from   : install.sh"
echo "PHP version               : ${PHP_VERSION}"
echo "Multicore Compilation     : ${MC}"
echo "Work directory            : ${PWD}"
echo "============================================"
echo


echo "---------- Install general dependencies ----------"
apt-get update \
&& apt-get install -y --no-install-recommends autoconf g++ libtool make \
libbz2-dev libxml2-dev libtidy-dev libxslt1-dev \
libzip-dev libc-client-dev libkrb5-dev libldap2-dev \
unixodbc-dev libgmp-dev libicu-dev libmagickwand-dev libsnmp-dev

echo "---------- Install bcmath ----------"
docker-php-ext-install ${MC} bcmath

echo "---------- Install bz2 libbz2-dev ----------"
docker-php-ext-install ${MC} bz2

echo "---------- Install calendar ----------"
docker-php-ext-install ${MC} calendar

echo "---------- Install dba ----------"
docker-php-ext-install ${MC} dba

echo "---------- Install exif ----------"
docker-php-ext-install ${MC} exif

echo "---------- Install gettext ----------"
docker-php-ext-install ${MC} gettext

echo "---------- Install gmp libgmp-dev ----------"
docker-php-ext-install ${MC} gmp

echo "---------- Install imap libc-client-dev libkrb5-dev ----------"
docker-php-ext-configure imap --with-kerberos --with-imap-ssl \
&& docker-php-ext-install ${MC} imap

echo "---------- Install imagick libmagickwand-dev ----------"
export CFLAGS="$PHP_CFLAGS" CPPFLAGS="$PHP_CPPFLAGS" LDFLAGS="$PHP_LDFLAGS" \
&& pecl install imagick-3.7.0 \
&& docker-php-ext-enable imagick

echo "---------- Install intl libicu-dev ----------"
docker-php-ext-install ${MC} intl

echo "---------- Install ldap libldap2-dev ----------"
docker-php-ext-configure ldap --with-ldap \
&& docker-php-ext-install ${MC} ldap

echo "---------- Install mysqli ----------"
docker-php-ext-install ${MC} mysqli

echo "---------- Install pdo_mysql ----------"
docker-php-ext-install ${MC} pdo_mysql

echo "---------- Install odbc pdo_odbc ----------"
docker-php-source extract; \
{ \
     echo '# https://github.com/docker-library/php/issues/103#issuecomment-271413933'; \
     echo 'AC_DEFUN([PHP_ALWAYS_SHARED],[])dnl'; \
     echo; \
     cat /usr/src/php/ext/odbc/config.m4; \
} > temp.m4; \
mv temp.m4 /usr/src/php/ext/odbc/config.m4; \
apt-get install -y --no-install-recommends unixodbc-dev; \
docker-php-ext-configure odbc --with-unixODBC=shared,/usr; \
docker-php-ext-configure pdo_odbc --with-pdo-odbc=unixODBC,/usr; \
docker-php-ext-install ${MC} odbc pdo_odbc; \
docker-php-source delete

echo "---------- Install pcntl ----------"
docker-php-ext-install ${MC} pcntl

echo "---------- Install pspell libpspell-dev ----------"
apt-get install -y --no-install-recommends libpspell-dev \
&& docker-php-ext-install ${MC} pspell

echo "---------- Install shmop ----------"
docker-php-ext-install ${MC} shmop

echo "---------- Install snmp libsnmp-dev ----------"
docker-php-ext-install ${MC} snmp

echo "---------- Install soap libxml2-dev ----------"
docker-php-ext-install ${MC} soap

echo "---------- Install sockets ----------"
docker-php-ext-install ${MC} sockets

echo "---------- Install sysvmsg ----------"
docker-php-ext-install ${MC} sysvmsg

echo "---------- Install sysvsem ----------"
docker-php-ext-install ${MC} sysvsem

echo "---------- Install sysvshm ----------"
docker-php-ext-install ${MC} sysvshm

echo "---------- Install tidy libtidy-dev ----------"
docker-php-ext-install ${MC} tidy

echo "---------- Install xmlrpc libxml2-dev ----------"
docker-php-ext-install ${MC} xmlrpc

echo "---------- Install xsl libxslt1-dev ----------"
docker-php-ext-install ${MC} xsl

echo "---------- Install zip libzip-dev ----------"
docker-php-ext-install ${MC} zip

echo "---------- Install zend opcache ----------"
docker-php-ext-configure opcache --enable-opcache \
&& docker-php-ext-install opcache

